package DAO.Impl;

import java.sql.Timestamp;
import java.util.*;

import org.hibernate.Query;
import org.hibernate.Session;

import DAO.Interfaces.IPersonnelDAO;
import DAO.Interfaces.IStoreDAO;
import POJO.Personnel;
import POJO.Store;

public class PersonnelDAOImpl extends GenericDAOImpl<Personnel> implements IPersonnelDAO{

	@Override
	public void updatePersonnel(Personnel person) {
		Session session = sessionFactory.openSession();
		ts = session.beginTransaction();

		Query query = session.createQuery("update Personnel set PNAME=:PNAME, PPT=:PPT, PADDRESS=:PADDRESS, PTEL=:PTEL, PDATE=:PDATE  where PID=:PID");
		query.setInteger("PID", person.getPID());
		query.setString("PNAME", person.getPNAME());
		query.setString("PPT", person.getPPT());
		query.setString("PADDRESS", person.getPADDRESS());
		query.setString("PTEL", person.getPTEL());
		query.setDate("PDATE", person.getPDATE());
		
		query.executeUpdate();
		ts.commit();
		session.close();
	}

	@Override
	public void deletePersonnel(Personnel staff) {
		Session session = sessionFactory.openSession();
		ts = session.beginTransaction();

		Query query = session.createSQLQuery("delete from personnel where S_ID=:SID");
		query.setInteger("SID", staff.getStore().getSID());
		
		query.executeUpdate();
		ts.commit();
		session.close();		
	}
}
